package engine;

/**
 * Class that represents a bigram. A bigram is composed by two words (left and right words).
 * 
 * @author ak2765.
 */
public final class BiGram {

	private final String leftWord;
	
	private final String rightWord;
	
	public BiGram(String leftWord, String rightWord) {
		if (leftWord == null) {
			throw new IllegalArgumentException("leftWord is null (right word is:" + rightWord + ")");
		}
		if (rightWord == null) {
			throw new IllegalArgumentException("rightWord is null (left word is: " + leftWord + ")");
		}

		
		this.leftWord = leftWord;
		this.rightWord = rightWord;
	}
	
	@Override
	public String toString() {
		return "BiGram[left=" + this.leftWord +", right=" + this.rightWord +"]";
	}

	/**
	 * Hash function for bigram.
	 */
	@Override
	public int hashCode() {
		return 13 * this.leftWord.hashCode() * this.rightWord.hashCode();
	}
	
	/**
	 * Returns whether or not the object passed as parameter is an equivalent bigram.
	 * @return Returns true if left and right words are the same, false otherwise.
	 */
	@Override
	public boolean equals(Object lhs) {
		BiGram lhsBiGram = (BiGram) lhs;
		
		return lhsBiGram.leftWord.equals(this.leftWord)
			&& lhsBiGram.rightWord.equals(this.rightWord);
	}
	
	public String getLeftWord() {
		return leftWord;
	}

	public String getRightWord() {
		return rightWord;
	}

}
